﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLTN.Entities;
using DLTN.Data;

public partial class Tour_Controls_ControlTourDocContent : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DisplayOnlyTour();
        }
    }

    // Hiển thị Tour độc
    private void DisplayOnlyTour()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";
        TList<LoaiTour> TList_LoaiTour = DataRepository.LoaiTourProvider.GetPaged("TenLoaiTour like N'%" + Common.TourDoc + "%'", "ID", 0, 0, out TotalRows);
        if (TList_LoaiTour.Count > 0)
        {
            TList<SubTour> TList_SubTour = DataRepository.SubTourProvider.GetPaged("IdLoaiTour=" + TList_LoaiTour[0].Id, "ID", 0, 0, out TotalRows);
            if (TList_SubTour.Count > 0)
            {
                WhereClause += " and IdSubTour =" + TList_SubTour[0].Id + "or IdSubTour=" + TList_SubTour[1].Id + "or IdSubTour=" + TList_SubTour[2].Id + "or IdSubTour=" + TList_SubTour[3].Id;
                TList<Tour> TList_Tour = DataRepository.TourProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 5, out TotalRows);
                if (TList_Tour.Count > 0)
                {
                    lblNgayCapNhat.Text = Common.StandardStringjquery(TList_Tour[0].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'"));

                    // Hiển thị 1 tour bên trái
                    strHTML += "<div id=\"tour-left-text\">";
                    strHTML += "<a href='Tour/" + TList_Tour[0].Id + "/" + TList_Tour[0].IdSubTour + "/" + GetTieuDe(TList_Tour[0].TieuDe) + ".aspx'>";
                    strHTML += "<img alt='" + TList_Tour[0].TieuDe + "' src='upload/Tour/" + TList_Tour[0].AnhDaiDien + "' width='374px' height='250px' style='padding-top:2px;'/></a>";
                    strHTML += "<div id='tieude-tour' style='margin:5px 0px;'>";
                    strHTML += "<a href='Tour/" + TList_Tour[0].Id + "/" + TList_Tour[0].IdSubTour + "/" + GetTieuDe(TList_Tour[0].TieuDe) + ".aspx'>";
                    strHTML += TList_Tour[0].TieuDe + "</a></div>";
                    strHTML += formatString(Server.HtmlDecode(TList_Tour[0].TomTat).ToString(), 150);
                    strHTML += "</div>";

                    ltrTourDocLeft.Text = strHTML;

                    strHTML = "";

                    // Hiển thị 4 tour bên phải
                    for (int i = 1; i < TList_Tour.Count; i++)
                    {
                        strHTML += "<div id='tour-right'>"; // BEGIN TOUR-RIGHT

                        strHTML += "<div id='tour-right-img'>"; // Begin tour-right-img
                        strHTML += "<a href='Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx'>";
                        strHTML += "<img alt='" + TList_Tour[0].TieuDe + "' src='upload/Tour/" + TList_Tour[i].AnhDaiDien + "' width='100px' height='80px'/></a>";
                        strHTML += "</div>"; // End tour-right-img

                        strHTML += "<div id='tour-right-text'>"; // Begin tour-right-text
                        strHTML += "<div id='tour-right-text-tieude'>";
                        strHTML += "<a href='Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx'>";
                        if (TList_Tour[i].TieuDe.Length > 38)
                            strHTML += formatString(TList_Tour[i].TieuDe, 37) + "</a>";
                        else
                            strHTML += TList_Tour[i].TieuDe + "</a>";

                        //strHTML += TList_Tour[i].TieuDe + "</a>"; 
                        strHTML += "</div>";

                            strHTML += formatString(Server.HtmlDecode(TList_Tour[i].TomTat.ToString()), 55);

                        strHTML += "</div>"; // End tour-right-text

                        strHTML += "</div>"; // END TOUR-RIGHT
                    }

                    ltrTourDocRight.Text = strHTML;
                }
            }
        }
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }


    public string formatString(string str, int n)
    {
        string kq = "";

        if (str.Length > n)
            kq = str.Substring(0, n + 1) + "...";
        else
            kq = str;

        return kq;
    }
}